package com.example.demo.threadCommunication;

import java.util.concurrent.CountDownLatch;

/**
 * @desc: <br/>
 * @author: Jingbo Hu<br/>
 * @time：2020年07⽉21⽇<br/>
 * @version：v1.0.0<br>
 */
public class CountDownLatchDemo {

    /**
     * 计数器必须大于等于0，只是等于0时候，计数器就是零，调用await方法时不会
     * 阻塞当前线程。CountDownLatch不可能重新初始化或者修改CountDownLatch对象的内部计数器的值
     */
    private static CountDownLatch c = new CountDownLatch(2);

    public static void main(String[] args) throws InterruptedException {

        Thread parse1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(1);
                c.countDown();
                System.out.println(2);
                c.countDown();
            }
        });

        parse1.start();

        c.await();

        System.out.println(3);
    }
}
